package fr.babos.test.utils 
{
	import com.adobe.nativeExtensions.Networkinfo.InterfaceAddress;
	import com.adobe.nativeExtensions.Networkinfo.NetworkInfo;
	import com.adobe.nativeExtensions.Networkinfo.NetworkInterface;
	import flash.display.DisplayObjectContainer;

	import flash.system.Capabilities;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import fr.babos.utils.EnvUtils;
	/**
	 * ...
	 * @author Pascal Achard
	 */
	public class UtilsTest 
	{
		
		/**
		 * Un displayObjectContainer
		 */
		private var _container:DisplayObjectContainer;
		
		public function UtilsTest(pContainer:DisplayObjectContainer) 
		{
			
			_container = pContainer;
			///////////////////////////////////
			// On teste la classe StringUtils
			///////////////////////////////////
			
			var src:String = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam scelerisque tempor lacus, non condimentum risus aliquet non. Donec eu consectetur turpis";
			
			// Retourne une string tronquée au bout de x caratères avec des "..." par défaut.
			/*trace(StringUtils.truncate(src, 50));
			
			// Retourne le nombre de mots.
			trace(StringUtils.wordCount(src));
			
			// Supprime un caractère spécifique.
			trace(StringUtils.remove(src, " "));
			
			// vérifie si une chaine existe et retourne combien de fois elle est présente.
			trace(StringUtils.countOf(src, "Done"));*/
			
			
			//////////////////////////////////
			// On teste la classe EnvUtils
			///////////////////////////////////
			
			trace(EnvUtils.toString());
			
			//showCapabilities();
			
			//showNetworkInfos();
			
		}
		
		private function showCapabilities():void {
            var tf:TextField = new TextField();
            tf.height = 600;
            tf.width = 400;
            tf.autoSize = TextFieldAutoSize.LEFT;
            tf.wordWrap = true;
            
            tf.text = "avHardwareDisable: " + Capabilities.avHardwareDisable +
                
                "\nhasAccessibility: " + Capabilities.hasAccessibility +
                "\nhasAudio: " + Capabilities.hasAudio +
                "\nhasAudioEncoder: " + Capabilities.hasAudioEncoder +
                "\nhasEmbeddedVideo: " + Capabilities.hasEmbeddedVideo +
                "\nhasIME: " + Capabilities.hasIME +
                "\nhasMP3: " + Capabilities.hasMP3 +
                "\nhasPrinting: " + Capabilities.hasPrinting +
                "\nhasScreenBroadcast: " + Capabilities.hasScreenBroadcast +
                "\nhasScreenPlayback: " + Capabilities.hasScreenPlayback +
                "\nhasStreamingAudio: " + Capabilities.hasStreamingAudio +
                "\nhasStreamingVideo: " + Capabilities.hasStreamingVideo +
                "\nhasTLS: " + Capabilities.hasTLS +
                "\nhasVideoEncoder: " + Capabilities.hasVideoEncoder +
                "\nisDebugger: " + Capabilities.isDebugger +
                "\nisEmbeddedInAcrobat: " + Capabilities.isEmbeddedInAcrobat +
                "\nlanguage: " + Capabilities.language +
                "\nlocalFileReadDisable: " + Capabilities.localFileReadDisable +
                "\nmanufacturer: " + Capabilities.manufacturer +
                "\nmaxLevelIDC: " + Capabilities.maxLevelIDC +
                "\nos: " + Capabilities.os +
                "\npixelAspectRatio: " + Capabilities.pixelAspectRatio +
                "\nplayerType: " + Capabilities.playerType +
                "\nscreenColor: " + Capabilities.screenColor +
                "\nscreenDPI: " + Capabilities.screenDPI +
                "\nscreenResolutionX: " + Capabilities.screenResolutionX +
                "\nscreenResolutionY: " + Capabilities.screenResolutionY +
                "\nserverString: " + Capabilities.serverString +
                "\ntouchscreenType: " + Capabilities.touchscreenType +
                
                // The following capabilities are supported only when publishing for AIR.
                // If you are publishing for AIR, uncomment the following lines.
                //"\nlanguages: " + Capabilities.languages +
                //"\ncpuArchitecture: " + Capabilities.cpuArchitecture +
                //"\nsupports32BitProcesses: " + Capabilities.supports32BitProcesses +
                //"\nsupports64BitProcesses: " + Capabilities.supports64BitProcesses +    
                                
                "\nversion: " + Capabilities.version;
                
            _container.addChild(tf);   
                
            trace("avHardwareDisable: " + Capabilities.avHardwareDisable);
            trace("hasAccessibility: " + Capabilities.hasAccessibility);
            trace("hasAudio: " + Capabilities.hasAudio);
            trace("hasAudioEncoder: " + Capabilities.hasAudioEncoder);
            trace("hasEmbeddedVideo: " + Capabilities.hasEmbeddedVideo);
            trace("hasIME: " + Capabilities.hasIME);
            trace("hasMP3: " + Capabilities.hasMP3);
            trace("hasPrinting: " + Capabilities.hasPrinting);
            trace("hasScreenBroadcast: " + Capabilities.hasScreenBroadcast);
            trace("hasScreenPlayback: " + Capabilities.hasScreenPlayback);
            trace("hasStreamingAudio: " + Capabilities.hasStreamingAudio);
            trace("hasStreamingVideo: " + Capabilities.hasStreamingVideo);
            trace("hasTLS: " + Capabilities.hasTLS);
            trace("hasVideoEncoder: " + Capabilities.hasVideoEncoder);
            trace("isDebugger: " + Capabilities.isDebugger);
            trace("isEmbeddedInAcrobat: " + Capabilities.isEmbeddedInAcrobat);
            trace("language: " + Capabilities.language);
            trace("localFileReadDisable: " + Capabilities.localFileReadDisable);
            trace("manufacturer: " + Capabilities.manufacturer);
            trace("maxLevelIDC: " + Capabilities.maxLevelIDC);
            trace("os: " + Capabilities.os);
            trace("pixelAspectRatio: " + Capabilities.pixelAspectRatio);
            trace("playerType: " + Capabilities.playerType);
            trace("screenColor: " + Capabilities.screenColor);
            trace("screenDPI: " + Capabilities.screenDPI);
            trace("screenResolutionX: " + Capabilities.screenResolutionX);
            trace("screenResolutionY: " + Capabilities.screenResolutionY);
            trace("serverString: " + Capabilities.serverString);
            trace("touchscreenType: " + Capabilities.touchscreenType);
            
            // The following capabilities are supported only when publishing for AIR.
            // If you are publishing for AIR, uncomment the following lines.       
            trace("cpuArchitecture: " + Capabilities.cpuArchitecture);
            trace("languages: " + Capabilities.languages);
            trace("supports32BitProcesses: " + Capabilities.supports32BitProcesses);
            trace("supports64BitProcesses: " + Capabilities.supports64BitProcesses);        
                        
            trace("version: " + Capabilities.version);
       
        }
		
		private function showNetworkInfos():void 
		{
			/*var interfaces:Vector.<NetworkInterface> = NetworkInfo.networkInfo.findInterfaces();
			
			for each (var interf:NetworkInterface in interfaces){
				var lcName:String = interf.name.toLowerCase();
				var isActive:Boolean = interf.active;
				var msg:String = "";
				if (lcName == "wifi"){
					msg = "Wifi " + (isActive ? "actif" : "désactivé");
				} else if (lcName == "mobile"){
					msg = "3G " + (isActive ? "actif" : "désactivé");
				} else {
					msg = "Autre interface";
				}
				trace (lcName + " : " + msg);
			}*/
			
			var ntf:Vector.<NetworkInterface> = NetworkInfo.networkInfo.findInterfaces();
			
			for each (var interfaceObj:NetworkInterface in ntf)
			{
				trace("Interface Name:" + interfaceObj.name + "\n" );
				trace("MTU:" + interfaceObj.mtu.toString + "\n" );
				trace("Display Name of the Interface:" + interfaceObj.displayName + "\n" );
				trace ("Active ?" + interfaceObj.active.toString() + "\n" );
				trace("Hardware Address:" + interfaceObj.hardwareAddress + "\n");
				
				for each(var address:InterfaceAddress in interfaceObj.addresses)
				{
					trace("Address" + address.address + "\n");
					trace("broadcast address" + address.broadcast + "\n");
					trace("ipversion" + address.ipVersion + "\n")
					trace("prefixlength" + address.prefixLength +"\n")
				}
				
				
			}
		}
		
		public function get container():DisplayObjectContainer 
		{
			return _container;
		}
		
	}

}